define(function(require, exports, module){
	var loginTemp = require("text!../template/login.html");
	module.exports = Nuui.View.extend({

		template:loginTemp,

		onRender:function(){

		},

		onShow:function(){
            var view = this;
            view.$(".box1").on("tap",function () {
                var text = view.$(".box1").text();
                if(text==""){
                    $(".box1").text('✔')
                }else {
                    $(".box1").text('')
                }
            });

            view.$("#login").on("tap", function(){
                /*App.loadingLayer.handleRequestComing();*/
                //判断用户协议是否勾选
                var text = view.$(".box1").text();
                if(text==""){
                    Nuui.utils.toast("请勾选用户协议");

                }else {
                    App.request(App.server.getServePath(App.path.getSessionId),{
                        data:{
                            loginName : view.$("#username").val(),
                            passWord : view.$("#password").val()
                        },
                        success:function(data){
                            // console.log(data);
                            if(data.body.errorCode==0){
                                var obj = {
                                    PSessionId: data.body.PSessionId
                                };
                                /*缓存PSessionId*/
                                App.storage.setCookieSession('PSessionId', obj);

                                var PSessionId = App.storage.getCookieSession("PSessionId");

                                App.storage.set("isUserLoggedIn",true);

                                var reg = /([^\|]*)\?.*!/;
                                var returnURL = decodeURIComponent(App.browseList[0].replace(reg,"$2")) && App.indexAnchor;

                                setTimeout(function(){
                                    App.navigate(returnURL, true);
                                },1000)
                            }else{
                                console.log('用户名或密码错误');
                            }

                        },
                        complete:function(){
                            setTimeout(function(){
                                App.loadingLayer.handleRequestComplete();
                            },500)
                        }
                    });
                }
                return false;
            });

		}
	});
});
